<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
 lang="en" dir="ltr">
<head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><link rel="stylesheet" href="../codebase/default.css" type="text/css" media="screen" title="no title" charset="utf-8"><title>
    dhtmlxconnector:filtering    [Skin test wiki]
  </title></head>

<body>
<div class="dokuwiki">
  
  <div class="stylehead">

    <div class="header">
    <a class="logo" href="http://dhtmlx.com" title="DHTMLX Documentation homepage"></a>
    <span class="tittle-dhtmlx">DHTMLX Docs & Samples Explorer</span>

    <div class="search-field">
        <form action="http://dhtmlx.com/dhxdocs/doku.php" accept-charset="utf-8" id="dw__search"><div class="no"><input type="hidden" name="do" value="search" /><input type="text" id="qsearch__in" accesskey="f" name="id" title="Search" /><button type="submit"></button><div id="qsearch__out" class="ajax_qsearch JSpopup"></div></div></form>    </div>
        <div class="buttons">
                <a class="doc"></a>
                <a title="DHTMLX Samples homepage" href="../samples.html" class="sample"/></a>
        </div>
     <!-- <div class="pagename">
        [[<a href="#"  title="Backlinks">dhtmlxconnector:filtering</a>]]
      </div>
      <div class="logo">
        <a href="/dhtmlx/_lab/wiki/doku.php"  name="dokuwiki__top" id="dokuwiki__top" accesskey="h" title="[H]">Skin test wiki</a>      </div>

      <div class="clearer"></div>-->
        
    </div>

    
<!--   <div class="bar" id="bar__top">
      <div class="bar-left" id="bar__topleft">
                <form class="button btn_revs" method="get" action="http://dhtmlx.com/dhxdocs/doku.php"><div class="no"><input type="hidden" name="do" value="revisions" /><input type="hidden" name="id" value="dhtmlxconnector:filtering" /><input type="submit" value="Old revisions" class="button" accesskey="o" title="Old revisions [O]" /></div></form>      </div>

      <div class="bar-right" id="bar__topright">
        <form class="button btn_recent" method="get" action="http://dhtmlx.com/dhxdocs/doku.php"><div class="no"><input type="hidden" name="do" value="recent" /><input type="hidden" name="id" value="dhtmlxconnector:filtering" /><input type="submit" value="Recent changes" class="button" accesskey="r" title="Recent changes [R]" /></div></form>        <form action="http://dhtmlx.com/dhxdocs/doku.php" accept-charset="utf-8" id="dw__search"><div class="no"><input type="hidden" name="do" value="search" /><input type="text" id="qsearch__in" accesskey="f" name="id" title="Search" /><button type="submit"></button><div id="qsearch__out" class="ajax_qsearch JSpopup"></div></div></form>&nbsp;
      </div>

      <div class="clearer"></div>
    </div> -->

<!--        <div class="breadcrumbs">
      <span class="bchead">Trace:</span> <span class="bcsep">&raquo;</span> <span class="curid"><a href="/dhtmlx/_lab/wiki/doku.php?id=dhtmlxconnector:filtering"  class="breadcrumbs" title="dhtmlxconnector:filtering">filtering</a></span>    </div>
    -->

    
  </div>
  
  
  <div class="page">
    <!-- wikipage start -->
    
<p>
<div class='backlinks'><div class='backlink last_backlink'><img src="icons___file.gif"  class="media" alt="" /><a href="../index.html" class="wikilink1" title="start">Index</a></div><div class='arrow'></div><div class='backlink last_backlink'><img src="icons___connector.gif"  class="media" alt="" /><a href="index.html" class="wikilink1" title="dhtmlxconnector:toc">dhtmlxconnector</a></div><div class='arrow'></div><div class='backlink'><span class="curid"><a href="dhtmlxconnector___filtering.html" class="wikilink1" title="dhtmlxconnector:filtering">  Filtering  </a></span></div></div>

</p>

<h2><a name="filtering" id="filtering">Filtering</a></h2>
<div class="level2">

<p>
While all connector can <a href="dhtmlxconnector___url_manipulation.html" class="wikilink1" title="dhtmlxconnector:url_manipulation">filter data by url manipulation</a>, only Grid and TreeGrid<sup><a href="#fn__1" name="fnt__1" id="fnt__1" class="fn_top">1)</a></sup> has native <acronym title="Graphical User Interface">GUI</acronym> for sorting, so below info mostly actual for those two components.
</p>

<p>
To enable server side filtering you can use one of the following in-header filter types while configuring dhtmlxGrid:
</p>
<ul>
<li class="level1"><div class="li">#connector_text_filter - searches for values which contain mask defined through text field</div>
</li>
<li class="level1"><div class="li">#connector_select_filter - searches for values which contain mask defined through list of possible values</div>
</li>
</ul>
<pre class="code javascript">	mygrid.<a href='dhtmlxgrid___api_method_dhtmlxgridobject_setheader.html'><b><span class="me1">setHeader</span></b></a><span class="br0">&#40;</span><span class="st0">&quot;Column A, Column B&quot;</span><span class="br0">&#41;</span>;
	mygrid.<a href='dhtmlxgrid___api_method_dhtmlxgridobject_attachheader.html'><b><span class="me1">attachHeader</span></b></a><span class="br0">&#40;</span><span class="st0">&quot;#connector_text_filter,#connector_select_filter&quot;</span><span class="br0">&#41;</span></pre>
<p>
When using text filter, no any additional configuration necessary. Grid will automatically send data about new entered text and filter server side using %mask% pattern.
If you need change filtering pattern or implement more advanced logic - <a href="dhtmlxconnector___events_system.html" class="wikilink1" title="dhtmlxconnector:events_system">beforeFilter</a> server side event can be used
</p>

</div>

<h4><a name="redefining_filtering_through_beforefilter" id="redefining_filtering_through_beforefilter">Redefining filtering through beforeFilter</a></h4>
<div class="level4">

<p>
Event receives <a href="dhtmlxconnector___filterinterface_object.html" class="wikilink1" title="dhtmlxconnector:filterinterface_object">FilterInterface Object</a> as parameter
</p>

<p>
<strong>Define default filtering</strong>

</p>
<pre class="code php">   <span class="kw2">function</span> custom_filter<span class="br0">&#40;</span><span class="re0">$filter_by</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
          <span class="co1">//WHERE some_field LIKE 'value'</span>
          <span class="kw1">if</span> <span class="br0">&#40;</span><span class="sy0">!</span><a href="http://www.php.net/sizeof"><span class="kw3">sizeof</span></a><span class="br0">&#40;</span><span class="re0">$filter_by</span><span class="sy0">-&gt;</span><span class="me1">rules</span><span class="br0">&#41;</span><span class="br0">&#41;</span> 
               <span class="re0">$filter_by</span><span class="sy0">-&gt;</span><span class="me1">add</span><span class="br0">&#40;</span><span class="st0">&quot;some_field&quot;</span><span class="sy0">,</span><span class="st0">&quot;value&quot;</span><span class="sy0">,</span><span class="st0">&quot;LIKE&quot;</span><span class="br0">&#41;</span>;
   <span class="br0">&#125;</span>
   <span class="re0">$conn</span><span class="sy0">-&gt;</span><span class="me1">attach</span><span class="sy0">-&gt;</span><span class="me1">event</span><span class="br0">&#40;</span><span class="st0">&quot;beforeFilter&quot;</span><span class="sy0">,</span><span class="st0">&quot;custom_filter&quot;</span><span class="br0">&#41;</span>;</pre>
<p>
<strong>Redefine default filtering logic</strong>

</p>
<pre class="code php">   <span class="kw2">function</span> custom_filter<span class="br0">&#40;</span><span class="re0">$filter_by</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
          <span class="co1">//change WHERE some_field LIKE '%value%' to the WHERE some_field &gt; 'value'</span>
          <span class="re0">$index</span> <span class="sy0">=</span> <span class="re0">$filter_by</span><span class="sy0">-&gt;</span><span class="me1">index</span><span class="br0">&#40;</span><span class="st0">&quot;some_field&quot;</span><span class="br0">&#41;</span>;
          <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$index</span><span class="sy0">!==</span><span class="kw2">false</span><span class="br0">&#41;</span>  <span class="co1">//there is client side input for the filter</span>
               <span class="re0">$filter_by</span><span class="sy0">-&gt;</span><span class="me1">rules</span><span class="br0">&#91;</span><span class="re0">$index</span><span class="br0">&#93;</span><span class="br0">&#91;</span><span class="st0">&quot;operation&quot;</span><span class="br0">&#93;</span><span class="sy0">=</span><span class="st0">&quot;&gt;&quot;</span>;
   <span class="br0">&#125;</span>
   <span class="re0">$conn</span><span class="sy0">-&gt;</span><span class="me1">attach</span><span class="sy0">-&gt;</span><span class="me1">event</span><span class="br0">&#40;</span><span class="st0">&quot;beforeFilter&quot;</span><span class="sy0">,</span><span class="st0">&quot;custom_filter&quot;</span><span class="br0">&#41;</span>;</pre>
</div>

<h4><a name="custom_php_level_filters" id="custom_php_level_filters">Custom PHP level filters</a></h4>
<div class="level4">

<p>
By using beforeRender events it possible to define filtering rules as <acronym title="Hypertext Preprocessor">PHP</acronym> code ( will <strong> not work </strong> for dyn. modes ) 

</p>
<pre class="code php"><span class="kw2">function</span> custom_filter<span class="br0">&#40;</span><span class="re0">$data</span><span class="br0">&#41;</span><span class="br0">&#123;</span>
     <span class="kw1">if</span> <span class="br0">&#40;</span><span class="re0">$data</span><span class="sy0">-&gt;</span><span class="me1">get_value</span><span class="br0">&#40;</span><span class="st0">&quot;some&quot;</span><span class="br0">&#41;</span><span class="sy0">&lt;</span><span class="nu19">0</span><span class="br0">&#41;</span>
          <span class="re0">$data</span><span class="sy0">-&gt;</span><span class="me1">skip</span><span class="br0">&#40;</span><span class="br0">&#41;</span>; <span class="co1">//not include in output</span>
<span class="br0">&#125;</span>
<span class="re0">$conn</span><span class="sy0">-&gt;</span><span class="me1">event</span><span class="sy0">-&gt;</span><span class="me1">attach</span><span class="br0">&#40;</span><span class="st0">&quot;beforeRender&quot;</span><span class="sy0">,</span><span class="st0">&quot;custom_filter&quot;</span><span class="br0">&#41;</span></pre>
</div>

<h4><a name="filling_options_for_select_filter" id="filling_options_for_select_filter">Filling options for select filter</a></h4>
<div class="level4">

<p>

If you are using select filter you may need to define list of options in select box, it can be defined in one of 3 ways

</p>
<ul>
<li class="level1"><div class="li"> automatic - if no custom instruction provided , grid will use DISTINCT select against related field, and fetch all possible options</div>
</li>
<li class="level1"><div class="li"> hardcoded list </div>
</li>
</ul>
<pre class="code php">	<span class="re0">$grid</span><span class="sy0">-&gt;</span><span class="me1">set_options</span><span class="br0">&#40;</span><span class="st0">&quot;item_nm&quot;</span><span class="sy0">,</span><a href="http://www.php.net/array"><span class="kw3">array</span></a><span class="br0">&#40;</span><span class="st0">&quot;1&quot;</span><span class="sy0">,</span><span class="st0">&quot;two&quot;</span><span class="sy0">,</span><span class="st0">&quot;3&quot;</span><span class="br0">&#41;</span><span class="br0">&#41;</span>;
	<span class="re0">$grid</span><span class="sy0">-&gt;</span><span class="me1">render_table</span><span class="br0">&#40;</span><span class="st0">&quot;grid50&quot;</span><span class="sy0">,</span><span class="st0">&quot;item_id&quot;</span><span class="sy0">,</span><span class="st0">&quot;item_nm,item_cd&quot;</span><span class="br0">&#41;</span>;</pre><ul>
<li class="level1"><div class="li"> list created on base of different table</div>
</li>
</ul>
<pre class="code php">	<span class="re0">$filter1</span> <span class="sy0">=</span> <span class="kw2">new</span> OptionsConnector<span class="br0">&#40;</span><span class="re0">$res</span><span class="br0">&#41;</span>;
	<span class="re0">$filter1</span><span class="sy0">-&gt;</span><span class="me1">render_table</span><span class="br0">&#40;</span><span class="st0">&quot;countries&quot;</span><span class="sy0">,</span><span class="st0">&quot;country_id&quot;</span><span class="sy0">,</span><span class="st0">&quot;country_name(value)&quot;</span><span class="br0">&#41;</span>;
	<span class="re0">$grid</span><span class="sy0">-&gt;</span><span class="me1">set_options</span><span class="br0">&#40;</span><span class="st0">&quot;item_nm&quot;</span><span class="sy0">,</span><span class="re0">$filter1</span><span class="br0">&#41;</span>;
&nbsp;
	<span class="re0">$grid</span><span class="sy0">-&gt;</span><span class="me1">render_table</span><span class="br0">&#40;</span><span class="st0">&quot;grid50&quot;</span><span class="sy0">,</span><span class="st0">&quot;item_id&quot;</span><span class="sy0">,</span><span class="st0">&quot;item_nm,item_cd&quot;</span><span class="br0">&#41;</span>;</pre>
<p>
You can use both render_table and render_sql for OptionsConnector object, same as for any normal connector.
</p>

<p>
Beware that name of fields, used in select filter need to have alias <strong>(value)</strong>

</p>

</div>
<div class="footnotes">
<div class="fn"><sup><a href="#fnt__1" id="fn__1" name="fn__1" class="fn_bot">1)</a></sup> 
server side filtering with dhtmlxTreeGrid doesn&#039;t maintain open states</div>
</div>

    <!-- wikipage stop -->
  </div>

  <div class="clearer">&nbsp;</div>

  
  <div class="stylefoot">

    <div class="meta">
      <div class="user">
              </div>
     <!-- <div class="doc">
        dhtmlxconnector/filtering.txt &middot; Last modified: 2009/07/30 12:56 (external edit)      </div>
    </div>-->

   
    <!--<div class="bar" id="bar__bottom">-->
      <!--<div class="bar-left" id="bar__bottomleft">-->
        <!---->
        <!--<form class="button btn_revs" method="get" action="http://dhtmlx.com/dhxdocs/doku.php"><div class="no"><input type="hidden" name="do" value="revisions" /><input type="hidden" name="id" value="dhtmlxconnector:filtering" /><input type="submit" value="Old revisions" class="button" accesskey="o" title="Old revisions [O]" /></div></form>-->
      <!--</div>-->
      <!--<div class="bar-right" id="bar__bottomright">-->
        <!---->
        <!---->
        <!---->
        <!---->
        <!--<form class="button btn_login" method="get" action="http://dhtmlx.com/dhxdocs/doku.php"><div class="no"><input type="hidden" name="do" value="login" /><input type="hidden" name="sectok" value="ccb1ac691365fa427633468f6ee1f162" /><input type="hidden" name="id" value="dhtmlxconnector:filtering" /><input type="submit" value="Login" class="button" title="Login" /></div></form>-->
        <!--<form class="button btn_index" method="get" action="http://dhtmlx.com/dhxdocs/doku.php"><div class="no"><input type="hidden" name="do" value="index" /><input type="hidden" name="id" value="dhtmlxconnector:filtering" /><input type="submit" value="Index" class="button" accesskey="x" title="Index [X]" /></div></form>-->
        <!--<a class="nolink" href="#dokuwiki__top"><input type="button" class="button" value="Back to top" onclick="window.scrollTo(0, 0)" title="Back to top" /></a>&nbsp;-->
      <!--</div>-->
      <!--<div class="clearer"></div>-->
    <!--</div>-->

  </div>

  

</div>

<div class="footerinc">


</div>

<div class="no"><img src="/dhtmlx/_lab/wiki/lib/exe/indexer.php?id=dhtmlxconnector%3Afiltering&amp;1257950922" width="1" height="1" alt=""  /></div>
     <div class="footer">
        <div class="footer-logo"></div>
        <div class="copyright">Copyright © 1998-2009 DHTMLX LTD.<br />All rights reserved.</div>
            	    </div>
</body>
</html>
